<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<title>c - argc and argv in main - Stack Overflow</title>
<link rel="shortcut icon" href="http://sstatic.net/stackoverflow/img/favicon.ico">
<link rel="apple-touch-icon" href="http://sstatic.net/stackoverflow/img/apple-touch-icon.png">
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="http://sstatic.net/js/master.min.js?v=d761eb59f537"></script>
<link rel="stylesheet" type="text/css" href="http://sstatic.net/stackoverflow/all.css?v=e1214b61bb44">
<script type="text/javascript">
$(function () {
});
var imagePath='http://sstatic.net/stackoverflow/img/';

</script>

    <link rel="canonical" href="http://stackoverflow.com/questions/2020945/argc-and-argv-in-main">
    <link rel="alternate" type="application/atom+xml" title="Feed for question 'argc and argv in main'" href="/feeds/question/2020945">
    <script src="http://sstatic.net/js/question.js?v=8ab4110b4399" type="text/javascript"></script>
    <script type="text/javascript">
        
        StackExchange.ready(function () {

            StackExchange.question.init({questionId:2020945});

            styleCode();
        });
    </script>


    <script type="text/javascript">
        StackExchange.init({"stackAuthUrl":"http://stackauth.com","site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers"},"user":{"isAnonymous":true,"fkey":"2b3dd56f6b85919481197aa2cc1707cd","inboxUnviewedCount":-1}});
    </script>

</head>
<body class="question-page">
    <noscript><div id="noscript-padding"></div></noscript>
    <div id="notify-container"></div>

    <div id="overlay-header"></div>
    <div id="custom-header"></div>
    <div class="container">
        <div id="header">
            <div id="portalLink">
                <a class="genu" href="http://stackexchange.com">Stack Exchange</a>
            </div>
            <div id="topbar">
                <div id="hlinks">
                    <span id="hlinks-user">
                  
                  </span>
                  <span id="hlinks-nav">
                  <a href="/users/login?returnurl=%2fquestions%2f2020945%2fargc-and-argv-in-main">log in</a>
 <span class="lsep">|</span>
<a href="http://careers.stackoverflow.com">careers</a>
 <span class="lsep">|</span>

                  </span>
                  <span id="hlinks-custom">
                  <a href="http://chat.stackoverflow.com">chat</a>
 <span class="lsep">|</span>
<a href="http://meta.stackoverflow.com">meta</a>
 <span class="lsep">|</span>
<a href="/about">about</a>
 <span class="lsep">|</span>
<a href="/faq">faq</a>
                  </span>
                </div>
                <div id="hsearch">
                    <form id="search" action="/search" method="get">
                    <div>
                        <input name="q" class="textbox" tabindex="1" onfocus="if (this.value=='search') this.value = ''" type="text" maxlength="140" size="28" value="search">
                    </div>
                    </form>
                </div>
            </div>
            <br class="cbt">
            <div id="hlogo">
                <a href="/">Stack Overflow</a>
            </div>
            <div id="hmenus">
                <div class="nav mainnavs">
                    <ul>
                        <li class="youarehere"><a id="nav-questions" href="/questions">Questions</a></li>
                        <li><a id="nav-tags" href="/tags">Tags</a></li>
                        <li><a id="nav-users" href="/users">Users</a></li>
                        <li><a id="nav-badges" href="/badges">Badges</a></li>
                        <li><a id="nav-unanswered" href="/unanswered">Unanswered</a></li>
                    </ul>
                </div>
                <div class="nav askquestion">
                    <ul>
                        <li>
                            <a id="nav-askquestion"  href="/questions/ask">Ask Question</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div id="content">
            



<div id="question-header">
    <h1><a href="/questions/2020945/argc-and-argv-in-main" class="question-hyperlink">argc and argv in main</a></h1>
</div>

<div id="mainbar">


<div id="question">

    <div class="everyonelovesstackoverflow" id="adzerk1">
    </div>

    
    <table>
    <tr>
    <td class="votecell">
        
<div class="vote">
    <input type="hidden" value="2020945">
    <a class="vote-up-off" title="This question is useful and clear (click again to undo)">up vote</a>
    <span class="vote-count-post">3</span>
    <a class="vote-down-off" title="This question is unclear or not useful (click again to undo)">down vote</a>

    <a class="star-off" href="#" title="This is a favorite question (click again to undo)">favorite</a>
    <div class="favoritecount"><b>1</b></div>    

</div>

    </td>
    <td class="postcell">
        <div>          
            <div class="post-text">
                <pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#define MAXLINE 1000

int getline(char *s, int lim)
{
    int i = 0;

    while(i &lt; lim - 1 &amp;&amp; (*s = getchar()) != EOF &amp;&amp; *s++ != '\n')
       i++;

    if(*s == '\n')
      *s++ = '\n', i++;

    *s = '\0';
    return i;
}
int main(int argc, char *argv[])
{   

     char line[MAXLINE];
     long lineno = 0;
     int c, except = 0, number = 0, found = 0;

     while(--argc &gt; 0 &amp;&amp; (*++argv)[0] == '-')
        while(c = *++argv[0])
          switch(c) {
             case 'x':
                  except = 1;
                  break;
             case 'n':
                  number = 1;
                  break;
             default:
                  printf("find: illegal option %c\n", c);
                  argc = 0;
                  found = -1;
                  break;
          }

     if(argc != 1)
         printf("Usage: find -x -n pattern\n");
     else
         while(getline(line, MAXLINE) &gt; 0) {
             lineno++;
             if((strstr(line, *argv) != NULL) != except) {
                   if(number)
                      printf("%ld:", lineno);
                   printf("%s", line);
                   found++;
             }
         }

     printf("Found: %d", found);
     return found;
}
</code></pre>

<p>while(--argc > 0 &amp;&amp; (*++argv)[0] == '-')</p>

<p>Does this expression in the parantheses (*++argv)[0] differs from while(c = *++argv[0]) without parantheses?</p>

<p>If so, in what? Does (*++argv) means pointer to the next argument, and *++argv[0] means pointer to the next character in the current char array which is being pointed at?</p>

            </div>            
            <div class="post-taglist">
                <a href="/questions/tagged/c" class="post-tag" title="show questions tagged 'c'" rel="tag">c</a> <a href="/questions/tagged/pointers" class="post-tag" title="show questions tagged 'pointers'" rel="tag">pointers</a> <a href="/questions/tagged/string" class="post-tag" title="show questions tagged 'string'" rel="tag">string</a> 
            </div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/q/2020945" title="short permalink to this question">link</a><span class="lsep">|</span><a href="/posts/2020945/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2020945" title="flag this post for serious problems or moderator attention">flag</a></div>
            </td>
                        

            <td class="post-signature owner">
            <div class="user-info"><div class="user-action-time">asked <span title="2010-01-07 14:26:59Z" class="relativetime">Jan 7 '10 at 14:26</span></div><div class="user-gravatar32"><a href="/users/214547/tool"><img src="http://www.gravatar.com/avatar/4928d9592441561b53f2badded75ec86?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/214547/tool">Tool</a><br><span class="reputation-score" title="reputation score">199</span><span title="1 silver badge"><span class="badge2"></span><span class="badgecount">1</span></span><span title="8 bronze badges"><span class="badge3"></span><span class="badgecount">8</span></span></div></div>
                <br class="cbt">
                <div class="accept-rate accept-answer-link" title="this user has accepted an answer for 18 of 22 eligible questions">82% accept rate</div>
            </td>
            </tr>
            </table>
        </div>
    </td>
    </tr>

    

<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2020945" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1942948" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">Im also interested about one thing:

while(c = *++argv[0])
this expression. Does this actually means: while(c = *++argv[0] != 0), i mean does *++argv[0] returns a null pointer to c if it hasnt found a character?
</span> &ndash;&nbsp;<a href="/users/214547/tool" title="199 reputation" class="comment-user owner">Tool</a> <span class="comment-date"><span title="2010-01-07 14:38:14Z">Jan 7 '10 at 14:38</span></span></div></td>
    </tr>
            
    <tr id="comment-1943090" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">yes - answered below.</span> &ndash;&nbsp;<a href="/users/121332/alex-brown" title="6741 reputation" class="comment-user">Alex Brown</a> <span class="comment-date"><span title="2010-01-07 14:55:54Z">Jan 7 '10 at 14:55</span></span></div></td>
    </tr>
            
    <tr id="comment-1943110" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">Oh! Thanks for the explanations! :)</span> &ndash;&nbsp;<a href="/users/214547/tool" title="199 reputation" class="comment-user owner">Tool</a> <span class="comment-date"><span title="2010-01-07 14:59:24Z">Jan 7 '10 at 14:59</span></span></div></td>
    </tr>
            
    <tr id="comment-1943389" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">As noted in my answer, see K&amp;R&#39;s errata entry on this code: <a href="http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html" rel="nofollow">cm.bell-labs.com/cm/cs/cbook/2ediffs.html</a></span> &ndash;&nbsp;<a href="/users/226621/alok" title="14484 reputation" class="comment-user">Alok</a> <span class="comment-date"><span title="2010-01-07 15:27:58Z">Jan 7 '10 at 15:27</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
    
    </table>    
</div>



<div id="answers">

    <a name="tab-top"></a>
    <div id="answers-header">
        <div class="subheader answers-subheader">
            <h2>6 Answers</h2>
            <div id="tabs">
                <a href="/questions/2020945/argc-and-argv-in-main?tab=active#tab-top" title="Answers with the latest activity first">active</a>
<a href="/questions/2020945/argc-and-argv-in-main?tab=oldest#tab-top" title="Answers in the order they were provided">oldest</a>
<a class="youarehere" href="/questions/2020945/argc-and-argv-in-main?tab=votes#tab-top" title="Answers with the highest score first">votes</a>

            </div>
        </div>
    </div>


    <a name="2021328"></a>
    
    <div id="answer-2021328" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2021328">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">11</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>
<span class="vote-accepted-on" title="The question owner accepted this as the best answer Jan 7 '10 at 16:39">accepted</span>
</div>

        </td>
        <td>
            <div class="post-text"><p>First, K&amp;R have an errata on this particular snippet:</p>

<blockquote>
  <p>117(§5.10): In the <em>find</em> example, the program increments <code>argv[0]</code>. This is not specifically forbidden, but not specifically allowed either.</p>
</blockquote>

<p>Now for the explanation.</p>

<p>Let's say your program is named <code>prog</code>, and you execute it with: <code>prog -ab -c Hello World</code>.  You want to be able to parse the arguments to say that options <code>a</code>, <code>b</code> and <code>c</code> were specified, and <code>Hello</code> and <code>World</code> are the non-option arguments.</p>

<p><code>argv</code> is of type <code>char **</code>&mdash;remember that an array parameter in a function is the same as a pointer.  At program invocation, things look like this:</p>

<pre><code>                 +---+         +---+---+---+---+---+
 argv ----------&gt;| 0 |--------&gt;| p | r | o | g | 0 |
                 +---+         +---+---+---+---+---+
                 | 1 |--------&gt;| - | a | b | 0 |
                 +---+         +---+---+---+---+
                 | 2 |--------&gt;| - | c | 0 |
                 +---+         +---+---+---+---+---+---+
                 | 3 |--------&gt;| H | e | l | l | o | 0 |
                 +---+         +---+---+---+---+---+---+
                 | 4 |--------&gt;| W | o | r | l | d | 0 |
                 +---+         +---+---+---+---+---+---+
                 | 5 |--------&gt;NULL
                 +---+
</code></pre>

<p>Here, <code>argc</code> is 5, and <code>argv[argc]</code> is <code>NULL</code>.  At the beginning, <code>argv[0]</code> is a <code>char *</code> containing the string <code>"prog"</code>.</p>

<p>In <code>(*++argv)[0]</code>, because of the parentheses, <code>argv</code> is incremented first, and then dereferenced.  The effect of the increment is to move that <code>argv ----------&gt;</code> arrow "one block down", to point to the <code>1</code>.  The effect of dereferencing is to get a pointer to the first commandline argument, <code>-ab</code>.  Finally, we take the first character (<code>[0]</code> in <code>(*++argv)[0]</code>) of this string, and test it to see if it is <code>'-'</code>, because that denotes the start of an option.</p>

<p>For the second construct, we actually want to walk down the string pointed to by the current <code>argv[0]</code> pointer.  So, we need to treat <code>argv[0]</code> as a pointer, ignore its first character (that is <code>'-'</code> as we just tested), and look at the other characters:</p>

<p><code>++(argv[0])</code> will increment <code>argv[0]</code>, to get a pointer to the first non- <code>-</code> character, and dereferencing it will give us the value of that character.  So we get <code>*++(argv[0])</code>.  But since in C, <code>[]</code> binds more tightly than <code>++</code>, we can actually get rid of the parentheses and get our expression as <code>*++argv[0]</code>.  We want to continue processing this character until it's <code>0</code> (the last character box in each of the rows in the above picture).</p>

<p>The expression</p>

<pre><code>c = *++argv[0]
</code></pre>

<p>assigns to <code>c</code> the value of the current option, and <em>has the value <code>c</code></em>.  <code>while(c)</code> is a shorthand for <code>while(c != 0)</code>, so the <code>while(c = *++argv[0])</code> line is basically assigning the value of the current option to <code>c</code> and testing it to see if we have reached the end of the current command-line argument.</p>

<p>At the end of this loop, argv will point to the first non-option argument:</p>

<pre><code>                 +---+         +---+---+---+---+---+
                 | 0 |--------&gt;| p | r | o | g | 0 |
                 +---+         +---+---+---+---+---+
                 | 1 |--------&gt;| - | a | b | 0 |
                 +---+         +---+---+---+---+
                 | 2 |--------&gt;| - | c | 0 |
                 +---+         +---+---+---+---+---+---+
 argv ----------&gt;| 3 |--------&gt;| H | e | l | l | o | 0 |
                 +---+         +---+---+---+---+---+---+
                 | 4 |--------&gt;| W | o | r | l | d | 0 |
                 +---+         +---+---+---+---+---+---+
                 | 5 |--------&gt;NULL
                 +---+
</code></pre>

<p>Does this help?</p>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2021328#2021328" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2021328/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2021328" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">edited <a href="/posts/2021328/revisions" title="show all edits to this post"><span title="2010-01-16 03:07:24Z" class="relativetime">Jan 16 '10 at 3:07</span></a></div><div class="user-gravatar32"></div><div class="user-details"><br></div></div>
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 15:22:18Z" class="relativetime">Jan 7 '10 at 15:22</span></div><div class="user-gravatar32"><a href="/users/226621/alok"><img src="http://www.gravatar.com/avatar/4ecd473d46f300f81636ee7034c358e2?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/226621/alok">Alok</a><br><span class="reputation-score" title="reputation score 14484">14.5k</span><span title="2 gold badges"><span class="badge1"></span><span class="badgecount">2</span></span><span title="15 silver badges"><span class="badge2"></span><span class="badgecount">15</span></span><span title="48 bronze badges"><span class="badge3"></span><span class="badgecount">48</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2021328" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1943987" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">Wow, really thanks for the effort. This really helped. </span> &ndash;&nbsp;<a href="/users/214547/tool" title="199 reputation" class="comment-user owner">Tool</a> <span class="comment-date"><span title="2010-01-07 16:40:55Z">Jan 7 '10 at 16:40</span></span></div></td>
    </tr>
            
    <tr id="comment-1944120" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">Very nice explanation.</span> &ndash;&nbsp;<a href="/users/50957/matt-jordan" title="760 reputation" class="comment-user">Matt Jordan</a> <span class="comment-date"><span title="2010-01-07 16:58:34Z">Jan 7 '10 at 16:58</span></span></div></td>
    </tr>
            
    <tr id="comment-1999459" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">+1 for pretty pictures.</span> &ndash;&nbsp;<a href="/users/10320/dreamlax" title="15164 reputation" class="comment-user">dreamlax</a> <span class="comment-date"><span title="2010-01-15 06:19:28Z">Jan 15 '10 at 6:19</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>

    <div class="everyonelovesstackoverflow" id="adzerk3">
    </div>

    
    <a name="2020977"></a>
    
    <div id="answer-2020977" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2020977">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">5</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>

</div>

        </td>
        <td>
            <div class="post-text"><p>Incrementing argv is a very bad idea, as once you have done so it is difficult to get the original value back. It is simpler, clearer and better to use an integer index - after all argv IS an array!</p>

<p>To answer your question ++argv increments the pointer. This then has indirection applied to it to get the first character.</p>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2020977#2020977" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2020977/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2020977" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 14:34:24Z" class="relativetime">Jan 7 '10 at 14:34</span></div><div class="user-gravatar32"><a href="/users/69307/anon"><img src="http://www.gravatar.com/avatar/ca2de18cb29118efc83a59ebc1f26849?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/69307/anon">anon</a><br><span class="reputation-score" title="reputation score 95102">95.1k</span><span title="13 gold badges"><span class="badge1"></span><span class="badgecount">13</span></span><span title="148 silver badges"><span class="badge2"></span><span class="badgecount">148</span></span><span title="407 bronze badges"><span class="badge3"></span><span class="badgecount">407</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2020977" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1943058" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">Actually, the indirection starts with the first character after the -, and each cycle it moves onto the next, to support clusters of option flags after a single - character.</span> &ndash;&nbsp;<a href="/users/121332/alex-brown" title="6741 reputation" class="comment-user">Alex Brown</a> <span class="comment-date"><span title="2010-01-07 14:51:35Z">Jan 7 '10 at 14:51</span></span></div></td>
    </tr>
            
    <tr id="comment-1943078" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">I was referring to (*++argv)[0] == &#39;-&#39;</span> &ndash;&nbsp;<a href="/users/69307/anon" title="95102 reputation" class="comment-user">anon</a> <span class="comment-date"><span title="2010-01-07 14:54:32Z">Jan 7 '10 at 14:54</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>

    <a name="2020968"></a>
    
    <div id="answer-2020968" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2020968">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">5</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>

</div>

        </td>
        <td>
            <div class="post-text"><p>yes, you are correct.</p>

<pre><code>while(--argc &gt; 0 &amp;&amp; (*++argv)[0] == '-')
</code></pre>

<p>is scanning the array (of length argc) of command line arguments one by one looking for those starting with a <code>-</code> option prefix.  For each of those:</p>

<pre><code>while(c = *++argv[0])
</code></pre>

<p>is scanning through the set of switch characters that follow the first <code>-</code> in the current argument (i.e. <code>t</code> and <code>n</code> in <code>-tn</code>, until it hits the string null terminator <code>\0</code>, which terminates the while loop, since it evaluates as false.</p>

<p>This design allows both</p>

<pre><code>myApp -t -n
</code></pre>

<p>and </p>

<pre><code>myApp -tn
</code></pre>

<p>to both work and be understood as having the options <code>t</code> and <code>n</code>.</p>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2020968#2020968" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2020968/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2020968" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">edited <a href="/posts/2020968/revisions" title="show all edits to this post"><span title="2010-01-07 14:58:59Z" class="relativetime">Jan 7 '10 at 14:58</span></a></div><div class="user-gravatar32"></div><div class="user-details"><br></div></div>
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 14:32:52Z" class="relativetime">Jan 7 '10 at 14:32</span></div><div class="user-gravatar32"><a href="/users/121332/alex-brown"><img src="http://www.gravatar.com/avatar/3f0d8a55b2dacb482fe57b31ea260173?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/121332/alex-brown">Alex Brown</a><br><span class="reputation-score" title="reputation score">6,741</span><span title="1 gold badge"><span class="badge1"></span><span class="badgecount">1</span></span><span title="10 silver badges"><span class="badge2"></span><span class="badgecount">10</span></span><span title="32 bronze badges"><span class="badge3"></span><span class="badgecount">32</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2020968" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1943120" class="comment">
        <td class="comment-actions"><table><tbody><tr>
<td class="comment-score">
<span title="number of 'great comment' votes received" class="cool">1</span>
</td>
<td>
&nbsp;
</td></tr>
</tbody></table></td>
        <td class="comment-text"><div><span class="comment-copy">This design is simple and mostly reasonable, apart from the fact it modifies argc, and the contents of the array argv, which is poor design since it prevents any further use of these variables.</span> &ndash;&nbsp;<a href="/users/121332/alex-brown" title="6741 reputation" class="comment-user">Alex Brown</a> <span class="comment-date"><span title="2010-01-07 15:00:17Z">Jan 7 '10 at 15:00</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>

    <a name="2020978"></a>
    
    <div id="answer-2020978" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2020978">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">2</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>

</div>

        </td>
        <td>
            <div class="post-text"><p>Yes, the two expressions differ (though only slightly). IMO, this code is a bit on the excessively clever side. You'd be better off with something like this:</p>

<pre><code>for (int i=1; i&lt;argc; i++)
    if (argv[i][0] == '-') {
       size_t len = strlen(argv[i]);
       for (int j=0; j&lt;len; ++j)
           switch(argv[i][j]) {
               case 'x':
               // ...
</code></pre>

<p>This is pretty much equivalent to the code above, but I doubt anybody (who knows C at all) would have any difficulty figuring out what it really does.</p>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2020978#2020978" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2020978/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2020978" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">edited <a href="/posts/2020978/revisions" title="show all edits to this post"><span title="2010-01-07 14:52:51Z" class="relativetime">Jan 7 '10 at 14:52</span></a></div><div class="user-gravatar32"></div><div class="user-details"><br></div></div>
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 14:34:41Z" class="relativetime">Jan 7 '10 at 14:34</span></div><div class="user-gravatar32"><a href="/users/179910/jerry-coffin"><img src="http://www.gravatar.com/avatar/d8962238339d771f0348967be6f97b1b?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/179910/jerry-coffin">Jerry Coffin</a><br><span class="reputation-score" title="reputation score 76827">76.8k</span><span title="7 gold badges"><span class="badge1"></span><span class="badgecount">7</span></span><span title="38 silver badges"><span class="badge2"></span><span class="badgecount">38</span></span><span title="158 bronze badges"><span class="badge3"></span><span class="badgecount">158</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2020978" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1942967" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">but this code would not detect chains of options - you need another iterator to walk the chain of options -tn</span> &ndash;&nbsp;<a href="/users/121332/alex-brown" title="6741 reputation" class="comment-user">Alex Brown</a> <span class="comment-date"><span title="2010-01-07 14:41:16Z">Jan 7 '10 at 14:41</span></span></div></td>
    </tr>
            
    <tr id="comment-1943085" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">@Alex Brown: I believe I&#39;ve fixed that -- though I&#39;m not sure it&#39;s necessarily any real improvement. Allowing <code>-tn</code> instead of <code>-t -n</code> would have meant a fair amount when a typical terminal was a Teletype, but it&#39;s hardly worthwhile anymore.</span> &ndash;&nbsp;<a href="/users/179910/jerry-coffin" title="76827 reputation" class="comment-user">Jerry Coffin</a> <span class="comment-date"><span title="2010-01-07 14:55:13Z">Jan 7 '10 at 14:55</span></span></div></td>
    </tr>
            
    <tr id="comment-1943152" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">@Jerry It&#39;s entirely worthwhile. Every command-line user expects to be able to provide single-letter options in a group, and being lazy about the code means violating those strongly held expectations.

The deeper issue here is the custom-coding of this functionality, rather than the use of getopt or similar.</span> &ndash;&nbsp;<a href="/users/90002/novelocrat" title="4879 reputation" class="comment-user">Novelocrat</a> <span class="comment-date"><span title="2010-01-07 15:05:58Z">Jan 7 '10 at 15:05</span></span></div></td>
    </tr>
            
    <tr id="comment-1944237" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">@Novelocrat: I&#39;m afraid I can&#39;t really agree -- quite a few command line tools either don&#39;t allow clustered arguments at all, or have specific limitations about what arguments can and can&#39;t be clustered. Nobody with any substantial amount of experience can honestly have much expectation about this subject. Given that it only supports two arguments, neither with any associated parameter, I can see where using getopt would probably make the code more complex, so I can understand not using it, even though I agree that it <i>probably</i> should anyway.</span> &ndash;&nbsp;<a href="/users/179910/jerry-coffin" title="76827 reputation" class="comment-user">Jerry Coffin</a> <span class="comment-date"><span title="2010-01-07 17:10:03Z">Jan 7 '10 at 17:10</span></span></div></td>
    </tr>
            
    <tr id="comment-1946233" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">you try taking tar -xvzf a.tar.gz away from me and see what happens.  or ls -laTr, or ps -elF, etc, etc.</span> &ndash;&nbsp;<a href="/users/121332/alex-brown" title="6741 reputation" class="comment-user">Alex Brown</a> <span class="comment-date"><span title="2010-01-07 21:20:30Z">Jan 7 '10 at 21:20</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>

    <a name="2021123"></a>
    
    <div id="answer-2021123" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2021123">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">2</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>

</div>

        </td>
        <td>
            <div class="post-text"><p>The parentheses change the order in which the expressions are evaluated.</p>

<p>Without parentheses <code>*++argv[0]</code>:</p>

<ol>
<li><code>argv[0]</code> gets the pointer to character data currently pointed to by <code>argv</code>.</li>
<li><code>++</code> increments that pointer to the next character in the character array.</li>
<li><code>*</code> gets the character.</li>
</ol>

<p>with parentheses <code>(*++argv)[0]</code>:</p>

<ol>
<li><code>++argv</code> increments the argv pointer to point to the next argument.</li>
<li><code>*</code> defereferences it to obtain a pointer to the character data.</li>
<li><code>[0]</code> gets the first character in the character array.</li>
</ol>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2021123#2021123" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2021123/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2021123" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature">
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 15:00:55Z" class="relativetime">Jan 7 '10 at 15:00</span></div><div class="user-gravatar32"><a href="/users/30933/dave-cluderay"><img src="http://www.gravatar.com/avatar/74e6cc447a96a91d40ed5459cba61e15?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/30933/dave-cluderay">Dave Cluderay</a><br><span class="reputation-score" title="reputation score">2,427</span><span title="4 silver badges"><span class="badge2"></span><span class="badgecount">4</span></span><span title="8 bronze badges"><span class="badge3"></span><span class="badgecount">8</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2021123" class="comments dno">
        <table>
        <tbody>
        
            <tr><td></td><td></td></tr>
        
        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>

    <a name="2021975"></a>
    
    <div id="answer-2021975" class="answer">
        
        <table>
        <tr>
        <td class="votecell">
            
<div class="vote">
    <input type="hidden" value="2021975">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">0</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>

</div>

        </td>
        <td>
            <div class="post-text"><p>I did find a 'bug' in this program tho, entering myprogram.exe -xxxxnnnnn in the command line will actually work(as intended lol?). Should i fix K&amp;R's version about this?</p>
</div>
            <table class="fw">
            <tr>
            <td class="vt">
                <div class="post-menu"><a href="/questions/2020945/argc-and-argv-in-main/2021975#2021975" title="permalink to this answer">link</a><span class="lsep">|</span><a href="/posts/2021975/edit" title="edit this post">edit</a><span class="lsep">|</span><a id="flag-post-2021975" title="flag this post for serious problems or moderator attention">flag</a></div>
                
            </td>
            
            <td align="right" class="post-signature owner">   
            <div class="user-info"><div class="user-action-time">answered <span title="2010-01-07 16:48:11Z" class="relativetime">Jan 7 '10 at 16:48</span></div><div class="user-gravatar32"><a href="/users/214547/tool"><img src="http://www.gravatar.com/avatar/4928d9592441561b53f2badded75ec86?s=32&amp;d=identicon&amp;r=PG" height="32" width="32" alt=""></a></div><div class="user-details"><a href="/users/214547/tool">Tool</a><br><span class="reputation-score" title="reputation score">199</span><span title="1 silver badge"><span class="badge2"></span><span class="badgecount">1</span></span><span title="8 bronze badges"><span class="badge3"></span><span class="badgecount">8</span></span></div></div>
            </td>
            </tr>
            </table>
        </td>
        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-2021975" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-1944181" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">While that&#39;s not pretty, I wouldn&#39;t say that&#39;s a bug, as the value of except and number are still their expected values regardless of the number of &#39;x&#39; or &#39;n&#39; passed in. </span> &ndash;&nbsp;<a href="/users/50957/matt-jordan" title="760 reputation" class="comment-user">Matt Jordan</a> <span class="comment-date"><span title="2010-01-07 17:04:28Z">Jan 7 '10 at 17:04</span></span></div></td>
    </tr>
            
    <tr id="comment-1944251" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">yea, i guess the code would be too complicated and long to accept only -x and -n or -xn or -nx.</span> &ndash;&nbsp;<a href="/users/214547/tool" title="199 reputation" class="comment-user owner">Tool</a> <span class="comment-date"><span title="2010-01-07 17:11:12Z">Jan 7 '10 at 17:11</span></span><span class="edited-yes" title="this comment was edited"></span></div></td>
    </tr>
            
    <tr id="comment-1947394" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">This is the way everything else behaves too: <code>ls -ll</code> doesn&#39;t complain either.</span> &ndash;&nbsp;<a href="/users/226621/alok" title="14484 reputation" class="comment-user">Alok</a> <span class="comment-date"><span title="2010-01-08 00:09:12Z">Jan 8 '10 at 0:09</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
</td>
</tr>
        </table>
    </div>
    
    <a name='new-answer'></a>
    <form id="post-form" action="/questions/2020945/answer/submit" method="post" >
        <h2 class="space">Your Answer</h2>
        
<script type="text/javascript">
    $(function() {
     
        initTagRenderer("".split(" "), "".split(" "));

        lazyEditorReady('answer', true/* confirm navigation after wmd keypress */, "http://sstatic.net/Js/wmd.js?v=886d42f12268");
    });  
</script>




<div id="post-editor">  

    
    <div id="wmd-container">
        <div id="wmd-button-bar"></div>
        <textarea id="wmd-input" name="post-text" cols="92" rows="15" tabindex="101"></textarea>
    </div>

    <div class="fl" style="margin-top: 8px; height:24px;">&nbsp;</div>
    <div id="draft-saved" class="community-option fl" style="margin-top: 8px; height:24px; display:none;">draft saved</div>


    <div id="wmd-preview"></div>


    <div id="edit-block">
        <input id="fkey" name="fkey" type="hidden" value="2b3dd56f6b85919481197aa2cc1707cd">
        <input id="author" name="author" type="text">
    </div>
</div>
           
    <div class="form-item">
        <table>
        <tr>
        <td class="vm open-id-login">
            <a id="login-link" style="font-size: 200%; margin-left: 30px;" href="/users/login?returnurl=%2fquestions%2f2020945%2fargc-and-argv-in-main">log in</a>
            <script type="text/javascript">
                StackExchange.ready(function () {
                    StackExchange.helpers.onClickDraftSave('#login-link');
                });
            </script>
        </td>

    
        <td class="orcell">
            <div class="orword">or</div>
            <div class="orline"></div>
        </td>
        <td class="vm">
            <div>
                <label for="display-name">Name</label>
                <input id="display-name" name="display-name" type="text" size="30" maxlength="30" value="" tabindex="105">
            </div>
            <div>
                <label for="m-address">Email</label>
                <input id="m-address" name="m-address" type="text" size="40" maxlength="100" value="" tabindex="106">
                <span class="edit-field-overlay">never shown</span>
            </div>
            <div>
                <label for="home-page">Home Page</label>
                <input id="home-page" name="home-page" type="text" size="40" maxlength="200" value="" tabindex="107">
            </div>
        </td>
    
        </tr>
        </table>
    </div>
    
           
        
        
        <div class="form-submit cbt"><input id="submit-button" type="submit" value="Post Your Answer" tabindex="110"></div>
    </form>


    <h2 class="bottom-notice">
        Not the answer you're looking for? 
        Browse other questions tagged <a href="/questions/tagged/c" class="post-tag" title="show questions tagged 'c'" rel="tag">c</a> <a href="/questions/tagged/pointers" class="post-tag" title="show questions tagged 'pointers'" rel="tag">pointers</a> <a href="/questions/tagged/string" class="post-tag" title="show questions tagged 'string'" rel="tag">string</a> 
        or <a href="/questions/ask">ask your own question</a>.
    </h2>

</div>
</div>
<div id="sidebar">

<div class="module newuser newuser-greeting" style="display:none">
    <h4>Hello World!</h4>
    <div>
        <p>This is a collaboratively edited question and answer site for <b>professional and enthusiast programmers</b>. It's 100% free, no registration required.</p>
        <p class="ar"><a href="/about">about &raquo;</a>&nbsp;&nbsp;&nbsp;<a href="/faq">faq &raquo;</a></p>
    </div>
</div>    <div class="module">
        <p class="label-key">tagged</p>
        <div class="tagged"><a href="/questions/tagged/c" class="post-tag" title="show questions tagged 'c'" rel="tag">c</a>&nbsp;<span class="item-multiplier">&times;&nbsp;29276</span><br>
<a href="/questions/tagged/string" class="post-tag" title="show questions tagged 'string'" rel="tag">string</a>&nbsp;<span class="item-multiplier">&times;&nbsp;9080</span><br>
<a href="/questions/tagged/pointers" class="post-tag" title="show questions tagged 'pointers'" rel="tag">pointers</a>&nbsp;<span class="item-multiplier">&times;&nbsp;3270</span><br>
</div> 
        <p class="label-key">asked</p>
        <p class="label-value" title="2010-01-07 14:26:59Z">1 year ago</p>
        <p class="label-key">viewed</p>
        <p class="label-value">719 times</p>
        <p class="label-key">latest activity</p>
        <p class="label-value"><a href="?lastactivity" class="lastactivity-link" title="2010-01-16 03:07:24Z">1 year ago</a></p>
    </div>
    
    
        <script type="text/javascript">
            var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = "http://engine2.adzerk.net/z/8277/adzerk1_2_4_43,adzerk2_2_17_45,adzerk3_2_4_44?keywords=c,pointers,string"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);
        </script>
    
    <div class="everyonelovesstackoverflow" id="adzerk2">
    </div>

    
    <div>
        <script type="text/javascript">
            (function(){var q="http://careers.stackoverflow.com/Ad/js",g=location.search=="?golarge",a,d=100,c=location.hash.indexOf("#ninjas")>-1,f="Pretty",h="#adzerk2",b="#adzerk1",i="#herebeninjas";(function(){var b="min-height:220px;margin:15px 0",c=$("<div>").addClass("hireme").attr("style",b),a=$("<div>").html(c);document.write(a.html())})();$(function(){setTimeout(r,2e3);a=setTimeout(e,d)});var e=function(){clearTimeout(a);if(m()&&!k()){a=setTimeout(e,d);return}c=c||n();c&&$(b).css("height",$(b).outerHeight()).attr("id","stop-adzerk");if(l()&&!j()){a=setTimeout(e,d);return}g=g||o();f=g?"Large":f;p()},r=function(){clearTimeout(a);var b=$("div.hireme, "+i);b.each(function(){var a=$(this),d=a.html().replace(/\s+/g,"").length==0;if(d){var c=a,b=a.parents(".everyonelovesstackoverflow").first();if(b.length>0)c=b;c.remove()}})},l=function(){return $(h).length>0},j=function(){var a=$(h);return a.length==0?false:a.html().replace(/\s+/g,"").length>0},o=function(){return $("#careersadsdoublehigh").length>0},m=function(){return $(b).length>0},k=function(){var a=$(b);return a.length==0?false:a.html().replace(/\s+/g,"").length>0},n=function(){return $(i).length>0},p=function(){$.ajax({url:s(),dataType:"script",cache:true})},s=function(){return q+"?style="+f+"&gobanner="+c.toString()}})();
        </script>
    </div>

      

    <div class="module">
    <h4 id="h-linked">Linked</h4>
    <div class="linked">
    <div class="spacer">
<a href="/questions/2174881/why-have-a-pointer-to-a-pointer-int-a" class="question-hyperlink">Why have a pointer to a pointer (int **a)?</a>
</div>

    </div>
    </div>

    <div class="module">
    <h4 id="h-related">Related</h4>
    <div class="related">
    <div class="spacer">
<a href="/questions/659064/how-can-i-use-pointers-to-display-strings-in-an-array" class="question-hyperlink">How can I use pointers to display strings in an array?</a>
</div>
<div class="spacer">
<a href="/questions/1519885/defining-own-main-functions-arguments-argc-and-argv" class="question-hyperlink">Defining own main functions arguments argc and argv</a>
</div>
<div class="spacer">
<a href="/questions/1529170/c-if-else-and-pointers-returning-wrong-string" class="question-hyperlink">C - If/Else and Pointers Returning Wrong String</a>
</div>
<div class="spacer">
<a href="/questions/1706551/parse-string-into-argv-argc" class="question-hyperlink">Parse string into argv/argc</a>
</div>
<div class="spacer">
<a href="/questions/1814756/parsing-argc-and-argv-in-c" class="question-hyperlink">parsing argc and argv in c++</a>
</div>
<div class="spacer">
<a href="/questions/2753190/whats-wrong-with-my-using-argc-argv-this-way-in-c" class="question-hyperlink">What&#39;s wrong with my using argc/argv this way in c?</a>
</div>
<div class="spacer">
<a href="/questions/2791717/argc-argv-c-problems" class="question-hyperlink">Argc/Argv C Problems</a>
</div>
<div class="spacer">
<a href="/questions/3144316/when-main-is-defined-without-parameters-will-argc-and-argv-still-be-present-on-t" class="question-hyperlink">When main is defined without parameters, will argc and argv still be present on the stack?</a>
</div>
<div class="spacer">
<a href="/questions/3225507/return-array-of-strings" class="question-hyperlink">Return array of strings</a>
</div>
<div class="spacer">
<a href="/questions/3478046/why-isnt-main-defined-mainint-argc-stdvectorstdstring-argv" class="question-hyperlink">Why isn&#39;t main defined `main(int argc, std::vector&lt;std::string&gt; argv)` ?</a>
</div>
<div class="spacer">
<a href="/questions/3598351/reading-strings-with-undefined-length-in-c" class="question-hyperlink">Reading Strings with Undefined Length in C</a>
</div>
<div class="spacer">
<a href="/questions/3689235/is-there-any-way-to-improve-this-function-which-replaces-occurrences-of-substring" class="question-hyperlink">Is there any way to improve this function which replaces occurrences of substrings with another string in an malloc allocated string?</a>
</div>
<div class="spacer">
<a href="/questions/3743466/pointers-and-cstring-beginner-troubles" class="question-hyperlink">Pointers and cstring beginner troubles</a>
</div>
<div class="spacer">
<a href="/questions/3772796/argvargc" class="question-hyperlink">argv[argc] == ?</a>
</div>
<div class="spacer">
<a href="/questions/3898021/mainint-argc-char-argv" class="question-hyperlink">main(int argc, char *argv[])</a>
</div>
<div class="spacer">
<a href="/questions/4001085/using-malloc-for-double-pointers" class="question-hyperlink">using malloc() for double pointers</a>
</div>
<div class="spacer">
<a href="/questions/4005799/c-homework-1st-pointer-assignment" class="question-hyperlink">C Homework; 1st Pointer Assignment</a>
</div>
<div class="spacer">
<a href="/questions/4020543/in-c-what-is-the-proper-way-to-pass-a-pointer-to-a-string-from-a-function-to-the" class="question-hyperlink">in C what is the proper way to pass a pointer to a string from a function to the main.</a>
</div>
<div class="spacer">
<a href="/questions/4168244/c-split-store-string-of-x-length-into-an-array-of-structs" class="question-hyperlink">C - split/store string of X length into an array of structs</a>
</div>
<div class="spacer">
<a href="/questions/4322047/issue-with-printing-char-argvn-after-a-function-call-in-c" class="question-hyperlink">Issue with printing char *argv[n] after a function call in C</a>
</div>
<div class="spacer">
<a href="/questions/4380090/question-about-pointers-and-strings-in-c" class="question-hyperlink">Question about pointers and strings in C</a>
</div>
<div class="spacer">
<a href="/questions/4575801/objective-c-main-routine-what-is-int-argc-const-char-argv" class="question-hyperlink">Objective-c main routine, what is: int argc, const char * argv[]</a>
</div>
<div class="spacer">
<a href="/questions/4810393/reverse-a-string-using-pointers-in-a-function-output-in-main-is-garbled" class="question-hyperlink">Reverse a string using pointers in a function, output in main is garbled.</a>
</div>
<div class="spacer">
<a href="/questions/5191965/c-int-mainint-argc-char-argv" class="question-hyperlink">C++ - int main(int argc, char** argv)</a>
</div>
<div class="spacer">
<a href="/questions/5217395/c-int-mainint-argc-char-argv" class="question-hyperlink">C++ - int main(int argc, char *argv[])</a>
</div>

    </div>
    </div>

</div>


<div id="feed-link">
    <div id="feed-link-text"><a href="/feeds/question/2020945" title="feed of this question and its answers"><span class="feed-icon"></span>question feed</a></div>
</div>


<script type="text/javascript" src="/posts/2020945/ivc/e780"></script>
<noscript>
    <div><img src="/posts/2020945/ivc/e780" class="dno" alt=""></div>
</noscript>

<div style="display:none" id="prettify-lang">lang-c</div>
        </div>
    </div>
    <div id="footer">
        <div class="footerwrap">
            <div id="footer-menu">
                <a href="/about">about</a> |
                <a href="/faq">faq</a> |
                 <a href="http://blog.stackoverflow.com">blog</a> |
                    <a href="http://chat.stackoverflow.com">chat</a> |
                <a href="http://data.stackexchange.com">data</a> |
                <a href="http://itc.conversationsnetwork.org/series/stackoverflow.html">podcast</a> |
                <a href="/legal">legal</a> |
                <a href="http://engine.adzerk.net/redirect/0/2776/2751/0/4de3c60f719c4dfcb1a57531c7050090/0">advertising info</a> |
                <b><a href="mailto:team@stackoverflow.com">contact us</a></b>
                  | <b><a href="http://meta.stackoverflow.com">feedback always welcome</a></b>
                <div id="footer-sites">
                    
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://stackoverflow.com">stackoverflow.com</a>&nbsp; 
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://stackapps.com">api/apps</a>&nbsp; 
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://careers.stackoverflow.com">careers</a>&nbsp; 
                        <span style="color:#E8272C;font-size:140%">&#9632;</span>&nbsp;<a href="http://serverfault.com">serverfault.com</a>&nbsp; 
                        <span style="color:#00AFEF;font-size:140%">&#9632;</span>&nbsp;<a href="http://superuser.com">superuser.com</a>&nbsp; 
                        <span style="color:#969696;font-size:140%">&#9632;</span>&nbsp;<a href="http://meta.stackoverflow.com">meta</a>&nbsp; 
                        <span style="color:#46937D;font-size:140%">&#9632;</span>&nbsp;<a href="http://area51.stackexchange.com">area&nbsp;51</a>&nbsp; 
                        <span style="color:#C0D0DC;font-size:140%">&#9632;</span>&nbsp;<a href="http://webapps.stackexchange.com">webapps</a>&nbsp; 
                        <span style="color:#000000;font-size:140%">&#9632;</span>&nbsp;<a href="http://gaming.stackexchange.com">gaming</a>&nbsp; 
                        <span style="color:#dd4814;font-size:140%">&#9632;</span>&nbsp;<a href="http://askubuntu.com">ubuntu</a>&nbsp; 
                        <span style="color:#9ce4fe;font-size:140%">&#9632;</span>&nbsp;<a href="http://webmasters.stackexchange.com">webmasters</a>&nbsp; 
                        <span style="color:#cf4d3f;font-size:140%">&#9632;</span>&nbsp;<a href="http://cooking.stackexchange.com">cooking</a>&nbsp; 
                        <span style="color:#f4f28d;font-size:140%">&#9632;</span>&nbsp;<a href="http://gamedev.stackexchange.com">game development</a>&nbsp; 
                        <span style="color:#0f3559;font-size:140%">&#9632;</span>&nbsp;<a href="http://math.stackexchange.com">math</a>&nbsp; 
                        <span style="color:#f2f2f2;font-size:140%">&#9632;</span>&nbsp;<a href="http://photo.stackexchange.com">photography</a>&nbsp; 
                        <span style="color:#037187;font-size:140%">&#9632;</span>&nbsp;<a href="http://stats.stackexchange.com">stats</a>&nbsp; 
                        <span style="color:#f1e7cc;font-size:140%">&#9632;</span>&nbsp;<a href="http://tex.stackexchange.com">tex</a>&nbsp; 
                        <span style="color:#e1cdae;font-size:140%">&#9632;</span>&nbsp;<a href="http://english.stackexchange.com">english</a>&nbsp; 
                        <span style="color:#a2d9f6;font-size:140%">&#9632;</span>&nbsp;<a href="http://cstheory.stackexchange.com">theoretical cs</a>&nbsp; 
                        <span style="color:#1b3e6c;font-size:140%">&#9632;</span>&nbsp;<a href="http://programmers.stackexchange.com">programmers</a>&nbsp; 
                        <span style="color:#293a5d;font-size:140%">&#9632;</span>&nbsp;<a href="http://unix.stackexchange.com">unix</a>&nbsp;
                        <span style="color:#bec0cb;font-size:140%">&#9632;</span>&nbsp;<a href="http://apple.stackexchange.com">apple</a>&nbsp;
                        <span style="color:#939185;font-size:140%">&#9632;</span>&nbsp;<a href="http://wordpress.stackexchange.com">wordpress</a>&nbsp;
                        <span style="color:#b5cda4;font-size:140%">&#9632;</span>&nbsp;<a href="http://physics.stackexchange.com">physics</a>&nbsp;
                        <span style="color:#4176ab;font-size:140%">&#9632;</span>&nbsp;<a href="http://diy.stackexchange.com">home&nbsp;improvement</a>&nbsp;
                        <span style="color:#d1d8d7;font-size:140%">&#9632;</span>&nbsp;<a href="http://gis.stackexchange.com">gis</a>&nbsp;
                        <span style="color:#e5e2d3;font-size:140%">&#9632;</span>&nbsp;<a href="http://electronics.stackexchange.com">electronics</a>&nbsp;
                        <span style="color:#a4c639;font-size:140%">&#9632;</span>&nbsp;<a href="http://android.stackexchange.com">android</a>&nbsp;
                </div>
            </div>
            <div id="footer-flair">
                <a class="peer1" href="http://www.peer1.com/stackoverflow"></a>  
	            <a href="http://creativecommons.org/licenses/by-sa/2.5/" class="cc-wiki-link"></a>
                <div id="svnrev">rev 2011.3.28.2</div>
            </div>
            <div id="copyright">
                site design / logo &copy; 2011 stack exchange inc; 
                <a href="/questions-all">user contributions</a> licensed under <a href="http://creativecommons.org/licenses/by-sa/2.5/" rel="license">cc-wiki</a> with <a href="http://blog.stackoverflow.com/2009/06/attribution-required/" rel="license">attribution required</a>
            </div>
        </div>
    </div>
    
    <noscript>
        <div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
    </noscript>
    
    <script type="text/javascript">var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-5620270-1']);_gaq.push(['_trackPageview']);(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;ga.src='http://www.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();_qoptions={qacct:"p-c1rF4kxgLUzNc"};</script>
    <script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>
    
</body>
</html>